#include "dominion.h"
#include "dominion_helpers.h"
#include <string.h>
#include <stdio.h>
#include <assert.h>
#include "rngs.h"
#include "unittests.h"

int run_tests2() {
    int player1 = 0;
    int handCount = 5;
    int coppers[MAX_HAND];
    for (int i = 0; i < MAX_HAND; i++) {
        coppers[i] = copper;
    }

    struct gameState state;
    memset(&state, 0, sizeof(struct gameState)); // clear the game state
    int kingdom_cards[10] = {adventurer, council_room, feast, gardens, mine,
        remodel, smithy, village, baron, great_hall};

    // reset
    initializeGame(2, kingdom_cards, 1, &state); // initialize a new game
    state.handCount[player1] = handCount; // set the number of cards on hand
    memcpy(state.hand[player1], coppers, sizeof(int) * handCount); // set all the cards to copper

    printf("Testing updateCoins()\n");

    assert(updateCoins(player1, &state, 0) == 0);
    assert(state.coins == 5);
    printf("updateCoins() with a 5 copper treasures and no bonus passed\n");

    // reset
    memset(&state, 0, sizeof(struct gameState)); // clear the game state
    initializeGame(2, kingdom_cards, 1, &state); // initialize a new game
    state.handCount[player1] = handCount; // set the number of cards on hand
    memcpy(state.hand[player1], coppers, sizeof(int) * handCount); // set all the cards to copper

    assert(updateCoins(player1, &state, 2) == 0);
    assert(state.coins == 7);
    printf("updateCoins() with a 5 copper treasures and a bonus passed\n");

    // reset
    memset(&state, 0, sizeof(struct gameState)); // clear the game state
    initializeGame(2, kingdom_cards, 1, &state); // initialize a new game
    state.handCount[player1] = handCount; // set the number of cards on hand
    memcpy(state.hand[player1], coppers, sizeof(int) * handCount); // set all the cards to copper
    assert(gainCard(silver, &state, 2, player1) == 0); // add a silver to the player's hand
    assert(gainCard(gold, &state, 2, player1) == 0); // add a gold to the player's hand

    // We have 5 copper, 1 silver, 1 gold
    assert(updateCoins(player1, &state, 0) == 0);
    assert(state.coins == (5 + 1*2 + 1*3));
    printf("updateCoins() with a 5 copper, 1 silver, 1 gold and no bonus passed\n");


    printf("\n");

    return 0;
}